home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
madtrb31.arc
/
GRAPH.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-05-15
|
3KB
|
86 lines
Program Graphics; { Author: William P. Smith }
{ Mitchellville, Md }
{ This program generates a 3-D surface for the }
{ function Z=z(X,Y). }
Const
Thx = 0.2; {rotation }
Thy = 0.2; { angle }
n = 20; {# lines for detail -- 20 best for testing surfaces }
{ 50 for final picture }
Type
GraphFileName = String[15];
Var
cx,cy,sx,sy,delxp,delyp,xl,xu,yl,yu,dyp,dxp,
fx,fy,xp1,xp2,yp1,yp2,z1,z2,x,y,xp,yp: real;
i,j,xplot1,yplot1,xplot2,yplot2: integer;
q: char;
Ymax,Ymin: array[0..639] of integer; {for hidden line remover}
name: GraphFileName; {graph will be saved under name.pic}
scrnfil: file;
Buffer: Array[1..$4000] of Byte;
Video: Byte Absolute $B800:0000;
function z(x,y:real): real; { equation for surface }
var s:real;
begin
s:=sqr(x)+sqr(y); { this surface was used }
z:=cos(2*s)*exp(-0.5*s) { produce cosexp.pic }
end;
procedure GetGraph;
begin
cx:=cos(thx); cy:=cos(thy);
sx:=sin(thx); sy:=sin(thy);
write('x-range ');readln(xp1,xp2); { try -3 3 }
write('y-range ');readln(yp1,yp2); { -3 3 }
write('z-range ');readln(z1,z2); { 0 1 for above example }
delxp:=(xp2-xp1)/n; delyp:=(yp2-yp1)/n;
xl:=0.0; xu:=(xp2-xp1)*cx+(yp2-yp1)*cy;
yl:=-(xp2-xp1)*sx; yu:=(yp2-yp1)*sy+z2-z1;
fx:=640/xu; fy:=200/(yu-yl);
hires; hirescolor(15); { set color -- white is used here }
for i:=0 to 639 do begin
ymax[i]:=199; { initialize hidden line remover }
ymin[i]:=0;
end;
for i:=0 to n do begin
yp:=yp1+i*delyp; dyp:=yp-yp1; { project surface onto 640x200 }
x:=dyp*cy; y:=dyp*sy+z(xp1,yp)-z1; { pixel display.}
xplot1:=round(x*fx);
yplot1:=200-round((y-yl)*fy);
for j:=1 to 3*n do begin
xp:=xp1+j*delxp/3.0; dxp:=xp-xp1;
x:=dxp*cx+dyp*cy;
y:=-dxp*sx+dyp*sy+z(xp,yp)-z1;
xplot2:=round(x*fx);
yplot2:=200-round((y-yl)*fy);
if ymax[xplot2]>=yplot2 then begin { Plot and remove hidden lines}
ymax[xplot2]:=yplot2; { " }
draw(xplot1,yplot1,xplot2,yplot2,1); { " }
end; { " }
if ymin[xplot2]<=yplot2 then begin { " }
ymin[xplot2]:=yplot2; { " }
draw(xplot1,yplot1,xplot2,yplot2,1); { " }
end; { " }
xplot1:=xplot2; yplot1:=yplot2; { " }
end;
end;
end;
procedure GrafSave(name: GraphFileName); { Save Graph }
var i: integer;
begin
rewrite(scrnfil);
move(Video,Buffer,$4000);
Blockwrite(Scrnfil,Buffer,128);
close(scrnfil);
repeat until keypressed;
textmode(2);
end;
begin
write('Name for Graphics File? '); readln(name);
assign(scrnfil,name+'.pic');
GetGraph;
GrafSave(name);
end.